<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" href="__ADMIN__/static/index/css/common.css" />
		<link rel="stylesheet" href="__ADMIN__/static/index/css/reg.css" />
	</head>

	<body>
		<div class="middle">
			<a href="index.html"><img src="__ADMIN__/static/index/img/logo.jpg" alt="logo" /></a>
			<form id="reg" action="#" method="POST">
				<label>会员名</label><input type="text" name="user_name" id="user_name" />
				<div id="nametic" style="color: red;"></div>
				<br />
				<label>密码</label><input type="password" name="passwd" id="passwd" />
				<div id="passwdtip" style="color: red;"></div>
				<br />
				<label>确认密码</label><input type="password" id="comfirm_pwd" />
				<div id="comfirm_passwdtip" style="color: red;"></div>
				<br />
				<label>Email</label><input type="text" name="email" id="email" />
				<br />
				<label>手机号</label><input type="text" name="phone" id="phone" />
				<div id="phonetic" style="color: red;"></div>
				<br />
				<label>验证码</label><input type="text" id="code" name="code" />
				<span id="vali" style="cursor: pointer;"><img id="img_vali" src="{:url('index/reg/vali')}"></span>
				<span id="checked" style="cursor: pointer;">看不清，换一张</span>
				<br />
				<input type="checkbox" name="agree" id="agree" /><label for="agree">同意注册协议</label>

				<br />
				<!--<input type="submit" id="sub" name="sub" value="注册" onclick="alert('greg');"/>-->
				<input type="submit" id="sub" />
			</form>
		</div>
		<!--尾部-->
		{include file='public/_foot' /}
		<script type="text/javascript" src="__ADMIN__/static/index/js/reg.js"></script>
		<script type="text/javascript" src="__ADMIN__/static/index/js/jquery.min.js"></script>
		<script type="text/javascript" src="__ADMIN__/static/admin/lib/layer/2.4/layer.js"></script>
		<script>
		   	window.onload=function(){ 
				$('#vali').click(function(){
					 changevali();
				})
				$('#checked').click(function(){
					 changevali();
				})
				function changevali()
				{
					var img_src = $('#img_vali').attr('src');
					img_src  = img_src+'?'
					$('#img_vali').attr('src',img_src);
				}
				
				//账号格式判断
			    $('#user_name').blur(function(){
			    	var user_name = $('#user_name').val();
					if(user_name == '')
					{
						$('#nametic').text('账号不能为空！');
						return false;
					}else
					{
						$('#nametic').text('');
						var reg = /^[a-zA-Z]{1}\w{5,15}$/;
						var name_result = reg.exec(user_name);
						if(name_result == null)
						{
							$('#nametic').text('账号不能以数字开头，长度必须为6-16位,请重新输入！');
							return false;
						}else 
						{
							$('#nametic').text('');
							return false;
						}
					}
			    })
			    
			    //密码格式判断
			    $('#passwd').blur(function(){
			    	var passwd = $(this).val();
					if(passwd == '')
					{
						$('#passwdtip').text('密码不能为空！');
						return false;
					}else
					{
						$('#passwdtip').text('');
						var len = passwd.length;
						if(len<6 || len>16)
						{
							$('#passwdtip').text('密码长度必须为6-16位！');
							return false;
						}else 
						{
							$('#passwdtip').text('');
							return false;
						}
					}		
			    })
			    
			    //确认密码格式判断
			    $('#comfirm_pwd').blur(function(){
			    	var psd_confirm = $(this).val();
			    	var password = $('#passwd').val();
			    	switch(psd_confirm)
			    	{
			    		case '':
			    			$('#comfirm_passwdtip').text('');
			    			$('#comfirm_passwdtip').text('密码不能为空！');
			    		break;
			    		case password:
			    			$('#comfirm_passwdtip').text('');
			    		break;
			    		default:
			    			$('#comfirm_passwdtip').text('');
			    			$('#comfirm_passwdtip').text('密码不一致，请重新输入！');
			    	}	
			    })
			    
			    //电话格式判断
			    $('#phone').blur(function(){
			    	var tel = $(this).val();
					if(tel == '')
					{
						$('#phonetic').text('电话不能为空！');
						return false;
					}else
					{
						$('#phone').text('');
						var reg = /^\d{7,11}$/;
						var tel_result = reg.exec(tel);
						if(tel_result == null)
						{
							$('#phonetic').text('电话号码格式有误,请重新输入！');
							return false;
						}else
						{
							$('#phonetic').text('');
							return false;
						}
						return false;
					}
				})
				
				//Ajax请求
				$('#sub').click(function(){
//					alert(11);return false;
					var check = $('#agree').attr('checked');
//					alert(check);return false;
					if(check)
					{
						var user_name = $('input[name=user_name]').val();
						var passwd  = $('input[name=passwd]').val();
						var email  = $('input[name=email]').val();
						var phone  = $('input[name=phone]').val();
						var code = $('input[name=code]').val();
						var comfirm_pwd = $('input[name=comfirm_pwd]').val();
						if(
							user_name != '' &&
							passwd != '' &&
							phone != '' &&
							email != '' &&
							code != '' &&
							comfirm_pwd != ''
						)
						{
							$.ajax({
								type: 'POST',
								url: '{:url("index/reg/index")}',
								data: {user_name:user_name,passwd:passwd,email:email,phone:phone,code:code},
		//						dataType: 'json',
								success: function(data) {
		//							alert(data);return false;
									if(data==12001||data=='12001')
									{
										alert('注册成功');	
										window.location.href='{:url("index/login/index")}';
										return false;
									}
									else if(data==12004||data=='12004') 
									{
										alert('验证码错误');changevali();return false;
									}
									else if(data==12002||data=='12002') 
									{
										alert('该用户已存在');return false;
									}
									else if(data==12003||data=='12003') 
									{
										alert('该手机号码已被注册');return false;
									}
									else if(data==12000||data=='12000') 
									{
										alert('注册失败');return false;
									}
								},
								error: function(data) {
									console.log(data.msg);
								},
							});
						}
						else
						{
							alert('信息不完整，请重新输入！');
							return false;	
						}
					}else
					{
						alert('请同意注册协议');return false;
					}
				})
		    }

		</script>
	</body>

</html>